﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Gift.WebApp;

public partial class backstage_payment : System.Web.UI.Page
{
    // Fields

    protected string xmlPath = "/cn/xml/payment.xml";

    // Methods
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            if (base.Request.QueryString["id"] != null)
            {
                XmlDocument document = new XmlDocument();
                document.Load(base.Server.MapPath(this.xmlPath));
                XmlNodeList childNodes = document.SelectSingleNode("paymentMethod").ChildNodes;
                foreach (XmlNode node in childNodes)
                {
                    XmlElement element = (XmlElement)node;
                    if (element.GetAttribute("id") == base.Request.QueryString["id"])
                    {
                        element.SetAttribute("title", this.txtPaymentName.Value);
                        if (this.rdPayment0.Checked)
                        {
                            element.SetAttribute("checked", "false");
                        }
                        else if (this.rdPayment1.Checked)
                        {
                            element.SetAttribute("checked", "true");
                        }
                        element.SetAttribute("partner", this.txtPartnerID.Value);
                        element.SetAttribute("seller_email", this.txtSellerEmail.Value);
                        element.SetAttribute("key", this.txtKey.Value);
                        element.SetAttribute("remark", this.txtaRemark.Value);
                    }
                    else if (this.rdPayment0.Checked && (element.GetAttribute("id") != base.Request.QueryString["id"]))
                    {
                        element.SetAttribute("checked", "true");
                    }
                    else if (this.rdPayment1.Checked && (element.GetAttribute("id") != base.Request.QueryString["id"]))
                    {
                        element.SetAttribute("checked", "false");
                    }
                }
                document.Save(base.Server.MapPath(this.xmlPath));
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");location.href=\"payment_list.aspx\";</script>");
            }
        }
        catch
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
        }
        if (!(base.IsPostBack || (base.Request.QueryString["id"] == null)))
        {
            this.PayMentBind();
        }
    }

    protected void PayMentBind()
    {
        try
        {
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.xmlPath));
            XmlNodeList childNodes = document.SelectSingleNode("paymentMethod").ChildNodes;
            foreach (XmlNode node in childNodes)
            {
                XmlElement element = (XmlElement)node;
                if (element.GetAttribute("id") == base.Request.QueryString["id"])
                {
                    this.txtPaymentName.Value = element.GetAttribute("title");
                    if (element.GetAttribute("checked") == "true")
                    {
                        this.rdPayment1.Checked = true;
                    }
                    else
                    {
                        this.rdPayment0.Checked = true;
                    }
                    this.txtPartnerID.Value = element.GetAttribute("partner");
                    this.txtSellerEmail.Value = element.GetAttribute("seller_email");
                    this.txtKey.Value = element.GetAttribute("key");
                    this.txtaRemark.Value = element.GetAttribute("remark");
                }
            }
        }
        catch
        {
        }
    }

}